package plugin

import (
	"dingbot/config"
	"dingbot/database"
	"dingbot/errhelp"
	"dingbot/global"
	"dingbot/tools"
	"errors"
	"os"
	"time"
)

func CheckDatabase() {
	time.Sleep(time.Second * 3)
	if !tools.IsFileExist("plugin_data") {
		os.Mkdir("plugin_data", 0777)
	}
	_, DatabaseOk := database.AuthEmail(config.GetConfig().PocketBase.User, config.GetConfig().PocketBase.Password)
	if !DatabaseOk {
		errhelp.Tag(errors.New("数据库验证失败！"), "plugin-check")
		return
	}
	if !database.HaveCollection("plugins") {
		global.Logger.Info("正在创建plugin数据库...")
		database.CreateCollection("plugins", []database.SchemasModal{{Name: "name", Type: "text"}, {Name: "enable", Type: "bool"}})
	}
	init_plugin_ok = true
}
